clear
est clear


	use "$input/full_geoid_pair_panel.dta"
	
	bysort state_fips: egen max=max(storm)
		drop if max!=1


	drop if storm==0
	drop if migration==0
	
	replace totalapprovedihpamount=totalapprovedihpamount/1000000
	
	drop if totalapprovedihpamount<10 & totalapprovedihpamount!=.
	
	bysort from_geoid move_year: egen mean_exposure_mw=wtmean(total_storms), weight(migration)
	

		duplicates drop from_geoid move_year, force
		
		g storm_mw0=mean_exposure_mw
		g storm_mw1=home_total_storms
		
		keep from_geoid move_year storm_*
		
		reshape long storm_mw, i(from_geoid move_year) j(home)
		
		ttest storm_mw, by(home) unequal

		local m1 : di %9.2fc `r(mu_1)'
		local m2 : di %9.2fc `r(mu_2)'
		
		
		local s1 : di %9.2fc `r(sd_1)'
		local s2 : di %9.2fc `r(sd_2)'
		
		local x= `r(mu_1)'-`r(mu_2)'
		local diff : di %9.2fc `x'
		
		
	
		
	file open 	t 		using "$tables/table_si8.tex", replace write
	file write t	"\begin{table}[htbp]\footnotesize \centering" _n "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}" _n ///
						"\caption{Difference in storm exposure in storm-year migration, high damage storms}\label{tab: storm ttest high}" _n  ///
						"\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}}l*{9}{c}}" _n "\midrule" _n ///
						"&Mean&SE&\textit{t-stat}\\" _n ///
						"\midrule" _n ///
						"Receiving county storms&`m1'&`s1'&\\" _n ///
						"Sending county storms&`m2'&`s2'&\\" _n ///
						"\midrule" _n ///
						"Difference&`diff'&&`t'\\" _n ///
						"\midrule" _n ///
						"\end{tabular*}" _n ///
						"\begin{tabular*}{1\textwidth}{p{6.5in}}" _n ///
						"\footnotesize \textsc{Notes:} For counties that experience a high-damage storm, we calculate the total number of storms each county experiences over our full sample (Sending county storms). In each year a sending county experiences a storm, we calculate the weighted average total number of storms that the counties receiving migrants from that county in that year experience over our sample (Receiving county storms). Receiving counties are weighted based on the number of migrants they receive from a given county in a given year. We report the difference (a positive difference indicating that receiving counties experience more storms on average) and a t-test of the significance of that difference. We restrict the sample to those counties that have at least \$20 million in approved FEMA compensation (the top 90\% of storm impacted counties)." ///
							"\end{tabular*}" _n "\end{table}" _n 
	file close 	t		
	
	
	
	
	
			
	